const mongoose = require("./db");
//活动发布人

const announcerSchema = new mongoose.Schema({
    avatar: String,
    name: String,
    Verified: {//是否认证
        type: Boolean,
        default:true
    },
    fan: Number,//粉丝
    Brief: String,//简介
    Certification:String //认证类型
})
const announcermodel=mongoose.model('announcer',announcerSchema,'announcer')
//活动列表
const activitySchema = new mongoose.Schema({
    imgurl: String,
    title: String,
    time: String,
    type: String,
    price: Number,
    detailImg: String,
    address:Number,
    Preview: Number,//预览
    Save: Number,
    detail: [String],
    Free: { 
        type: String, 
        enum: ['672b242db42874319450de0d', '672b2435b42874319450de0f', ],  // 只允许免费/付费
        required: true 
      },
    Live: { 
        type: String, 
        enum: ['672b23fbb42874319450de09', '672b2406b42874319450de0b', ],  // 只允许上线/下线
        required: true 
    },
    aid: {
        type: mongoose.Types.ObjectId,
        ref:"announcer"
    }
})
let activitymodel=mongoose.model('activity',activitySchema,'activity')

//购物车表
const goshopSchema = new mongoose.Schema({
    img: String,
    name:String,
    title: String,
    num: Number,
    price: Number,
    coupon: Number,
    sid: {
        type: mongoose.Types.ObjectId,
        ref:'shop'
    },
    staus: {
        type: Boolean,
        default:false
    }
})
const goshopModel=mongoose.model('goshop',goshopSchema,'goshop')

//投诉表
const feedbackSchema = new mongoose.Schema({
    name: String,
    describe: String,
    imgurl: [String],
    phone: String,
    email: String,
    
})

const feedbackmodel = mongoose.model('feedback', feedbackSchema, 'feedback')
//活动类型表
const AtypeSchema = new mongoose.Schema({
    atname:String
})
const atypemodel = mongoose.model('atype', AtypeSchema, 'atype')
//二级类型
const BtypeSchema = new mongoose.Schema({
    btname: String,
    aid: {
        type: mongoose.Types.ObjectId,
        ref:'atype'
    }
})
const btypemodel =mongoose.model('btype', BtypeSchema, 'btype')
const ctypeSchema = new mongoose.Schema({
    ctname: String,
    bid: {
        type: mongoose.Types.ObjectId,
        ref:'btype'
    }
})
const ctypemodel = mongoose.model('ctype', ctypeSchema, 'ctype')

// 商品列表
const shopschema = new mongoose.Schema({
    name: String,
    price: Number,
    num:  {
        type: Number,
        default:0
    },
    imgurl: String,
    inventory: Number,
    postpaid: {
        type: Boolean,
        default:false
    },
    sales: Number,
    address: String,
    details: [String],
    album: [String],
    video: String,
    coupon: Number,
    Buy: [{
        imgurl: String,
        content: String,
        price: Number,
    }
    ]
})
const shopsmodel = mongoose.model('shop', shopschema, 'shop')
//商品评论
const shopCommentSchema = new mongoose.Schema({
    username: String,
    avatar: String,
    content:String,
    imgurl: [String],
    sid: {
        type: mongoose.Types.ObjectId,
        ref:'shop'
    },
    cid: {
        type: mongoose.Types.ObjectId,
        ref:'shopComment'
    }
   
})
const shopCommentModel = mongoose.model('shopComment', shopCommentSchema, 'shopComment')
//地址表
const addressSchema = new mongoose.Schema({
    address: String,
    detail: String,
    name: String,
    phone: String,
    default: {
        type: Boolean,
        default:false
    }
})
const addressmodel = mongoose.model("address", addressSchema, 'address')
//地址栏表
const dzSchema = new mongoose.Schema({
    text: String,
    value: String,
    aid: {
        type: mongoose.Types.ObjectId,
        ref:'dz'
    }
})
const dzmodel=mongoose.model('dz',dzSchema,'dz')
// 登录
const userSchema = new mongoose.Schema({
    username: String,
    imgurl: String,
    phone: String,
    password: String,
})
const user = mongoose.model("user", userSchema,'user');
// 民宿列表
const houseSchema = new mongoose.Schema({
    title: String,
    imgurl: String,
    price: Number,
    address: String,
    phone: String,
    type: [String],
    num: Number,
    pl: Number,
    detail: String,
})
const house = mongoose.model("house", houseSchema,'house');
// 民宿详情
const housedetailSchema = new mongoose.Schema({
    title: String,  // 房间标题
    imgurl: String, // 房间图片
    price: Number,// 房间价格
    gg: String,//规格
    zr: String,//入住几人
    pf: String,//平方
    sy: Number,//剩余几间
    hid:{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'house'
    }
})
const housedetail = mongoose.model("housedetail", housedetailSchema,'housedetail');
// 评论列表
const commentSchema = new mongoose.Schema({
    username: String, // 用户名
    hid:{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'house'
    },
    content: String, // 评论内容
    time: String, // 入住时间
    imgurl: String, // 用户头像
    star: Number, // 评分
    img: [String], // 评论图片
    fx: String // 房间类型
})
const comment = mongoose.model("comment", commentSchema,'comment');

// 民宿订单
const hshopModel = new mongoose.Schema({
    name: String, //订房间人
    phone: String, //电话
    price: Number, //价格
    imgurl: String, //房间图片
    datetime: {
        type: Date,
        default: Date.now
    }, //下单时间
    ddbh: String, //订单编号
    jname: String, //民宿名称
    fx: String, //房间类型
    num: Number, //入住天数
    status: {
        type: Boolean,
        default: false
    }, //订单状态
    hid:{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'housedetail'
    },
    time: [String], //入住时间
    date: String, //入住日期
})
const hshop = mongoose.model("hshop", hshopModel,'hshop');
module.exports = {
    user, house, shopCommentModel, dzmodel, atypemodel,
    btypemodel,ctypemodel,feedbackmodel,goshopModel,announcermodel,
    shopsmodel, housedetail, comment,addressmodel,hshop,activitymodel
};
